package com.iyundao.io.mapper;

import com.iyundao.io.model.SysUser;
import com.iyundao.io.model.SysUserInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

@Repository
public interface UserCustomMapper {

    @Results({
            @Result(column="sid", property="sid", jdbcType=JdbcType.CHAR, id=true),
            @Result(column="login_name", property="loginName", jdbcType=JdbcType.VARCHAR),
            @Result(column="show_name", property="showName", jdbcType=JdbcType.VARCHAR),
            @Result(column="real_name", property="realName", jdbcType=JdbcType.VARCHAR),
            @Result(column="login_pwd", property="loginPwd", jdbcType=JdbcType.VARCHAR),
            @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
            @Result(column="card_no", property="cardNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
            @Result(column="birthday", property="birthday", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="sex", property="sex", jdbcType=JdbcType.VARCHAR),
            @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
            @Result(column="detailed", property="detailed", jdbcType=JdbcType.VARCHAR),
            @Result(column="flag", property="flag", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_date", property="createDate", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="create_id", property="createId", jdbcType=JdbcType.CHAR),
            @Result(column="orde_by", property="ordeBy", jdbcType=JdbcType.TINYINT)
    })
    @Select("select * from sys_user where sid = (select uid from sys_user_info where openid=#{openid,jdbcType=VARCHAR})")
    SysUser selectByOpenid(String openid);

    @Select("select * from sys_user_info where openid=#{openid,jdbcType=VARCHAR}")
    SysUserInfo selectInfoByOpenid(String openid);

    @Results({
            @Result(column="sid", property="sid", jdbcType=JdbcType.CHAR, id=true),
            @Result(column="login_name", property="loginName", jdbcType=JdbcType.VARCHAR),
            @Result(column="show_name", property="showName", jdbcType=JdbcType.VARCHAR),
            @Result(column="real_name", property="realName", jdbcType=JdbcType.VARCHAR),
            @Result(column="login_pwd", property="loginPwd", jdbcType=JdbcType.VARCHAR),
            @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
            @Result(column="card_no", property="cardNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
            @Result(column="birthday", property="birthday", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="sex", property="sex", jdbcType=JdbcType.VARCHAR),
            @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
            @Result(column="detailed", property="detailed", jdbcType=JdbcType.VARCHAR),
            @Result(column="flag", property="flag", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_date", property="createDate", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="create_id", property="createId", jdbcType=JdbcType.CHAR),
            @Result(column="orde_by", property="ordeBy", jdbcType=JdbcType.TINYINT)
    })
    @Select("select * from sys_user where phone=#{phone,jdbcType=VARCHAR}")
    SysUser selectByPhone(String phone);

    @Results({
            @Result(column="sid", property="sid", jdbcType=JdbcType.CHAR, id=true),
            @Result(column="login_name", property="loginName", jdbcType=JdbcType.VARCHAR),
            @Result(column="show_name", property="showName", jdbcType=JdbcType.VARCHAR),
            @Result(column="real_name", property="realName", jdbcType=JdbcType.VARCHAR),
            @Result(column="login_pwd", property="loginPwd", jdbcType=JdbcType.VARCHAR),
            @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
            @Result(column="card_no", property="cardNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
            @Result(column="birthday", property="birthday", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="sex", property="sex", jdbcType=JdbcType.VARCHAR),
            @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
            @Result(column="detailed", property="detailed", jdbcType=JdbcType.VARCHAR),
            @Result(column="flag", property="flag", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_date", property="createDate", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="create_id", property="createId", jdbcType=JdbcType.CHAR),
            @Result(column="orde_by", property="ordeBy", jdbcType=JdbcType.TINYINT)
    })
    @Select("select * from sys_user where login_name=#{name,jdbcType=VARCHAR}")
    SysUser selectByLoginName(String name);

    @Update("update sys_user_info set uid=#{uid,jdbcType=CHAR} where openid=#{openid,jdbcType=VARCHAR}")
    int updateSysUserInfo(String uid,String openid);

    @Delete("delete from sys_user where sid=#{sid,jdbcType=VARCHAR}")
    int deleteUser(String sid);

    @Delete("delete from user_dept where uid=#{sid,jdbcType=VARCHAR}")
    int deleteUserDept(String sid);

    @Delete("delete from user_role where uid=#{sid,jdbcType=VARCHAR}")
    int deleteUserRole(String sid);

}
